<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;

/**
* 新闻管理
*/
class Weblink extends AdminBase
{
	public function index(){
		return $this->fetch('index',['list'=>db('link')->order('sort desc,add_time desc')->select()]);
	}
	public function add(){
		return $this->fetch('add');
	}
	public function save(){
		if($this->request->isPost()){
			$data = input('post.');
			if(db('link')->insert($data) !== false){
				$this->success('添加成功','index');
			}else{
				$this->error('提交失败');
			}
		}
	}
	public function edit($id){
		return $this->fetch('edit',['rows'=>db('link')->find($id)]);
	}
	public function update($id){
 		if($this->request->isPost()){
 			$data = input('post.');
 			if(db('link')->update($data) !== false){
 				$this->success('更新成功','index');
 			}else{
 				$this->error('更新失败');
 			}
 		}
	}
	/*
	 * 更新'0'或'1'
	 */
	public function flag($id){
        if (request()->isPost()) {
            $data = input('post.');
            if (db('link')->where(['id' => $id])->update($data) !== false) {
                $this->success('更新成功');
            } else {
                $this->error('更新失败');
            }
        }
    }
    public function delete($id = 0, $ids = [])
    {
        $id = $ids ? $ids : $id;
        if ($id) {
            if (db('link')->delete($id)) {
                $this->success('删除成功');
            } else {
                $this->error('删除失败');
            }
        } else {
            $this->error('请选择需要删除的项目');
        }
    }
}
	